
<template>
  <div class="header_information page-container">
    <!-- 头部 -->
    <el-row class="header_name">
      <el-col
        :span="24"
        class="header_text"
      >
        <h1>人员管理</h1>
      </el-col>
      <el-col :span="24">
        <div class="header_line"></div>
      </el-col>
    </el-row>
    <!-- 按钮 -->
    <el-row class="el_row_btn">
      <el-col
        :span="24"
        class="content"
      >
        <div class="content_top_btn">
          <div class="con_btn1">
            <el-button
              size="large"
              type="primary"
              @click="handleOpenBatchImportModal"
            >批量导入积分</el-button>
            <el-button
              size="large"
              type="primary"
              @click="handleOpenBatchAwardsModal"
            >批量导入奖项</el-button>

          </div>

          <el-space>
            <el-input
              class="top_search_inp"
              v-model.trim="query_data.studentName"
              placeholder="请输入姓名"
              clearable
            />
            <el-input
              class="top_search_inp"
              v-model.trim="query_data.phone"
              placeholder="请输入手机号"
              clearable
            />
            <!-- 组委会选择 -->
            <OrganizingSelect v-model="query_data.agentId" />
            <!-- 机构选择 -->
            <InstitutionSelect
              :disabled="!query_data.agentId"
              :agentId="query_data.agentId"
              v-model="query_data.institutionId"
            />
            <el-button
              size="large"
              :icon="Search"
              circle
              :loading="loading"
              @click="changeInp"
            />
          </el-space>
        </div>
      </el-col>
    </el-row>
    <!-- 内容 -->
    <el-row>
      <el-col :span="24">
        <el-table
          v-loading="loading"
          empty-text="暂无数据..."
          :data="tableData"
          border
          style="width: 100%"
        >
          <el-table-column
            label="ID"
            prop="studentId"
            width="100"
          />
          <el-table-column
            label="组委会名称"
            prop="agentName"
          />
          <el-table-column
            label="机构名称"
            prop="name"
          />
          <el-table-column
            label="姓名"
            prop="studentName"
          />
          <el-table-column
            label="手机号"
            prop="phone"
          />

          <el-table-column
            label="奖项"
            prop="awards"
          />
          <el-table-column
            label="城市赛积分"
            prop="cityIntegral"
          />
          <el-table-column
            label="锦标赛积分"
            prop="championship"
          />
          <el-table-column
            label="操作"
            prop="Address"
            width="100"
          >
            <template #default="scope">
              <el-dropdown
                trigger="click"
                @command="(value)=>handleOperate(value,scope.row)"
              >
                <span class="el_dropdown_link">
                  操作<el-icon class="el-icon--right"><arrow-down /></el-icon>
                </span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item
                      :icon="Edit"
                      command="edit-info"
                    > 编辑 </el-dropdown-item>
                    <el-dropdown-item
                      :icon="Delete"
                      command="delect-item"
                    > 删除 </el-dropdown-item>
                    <!-- <el-dropdown-item @click="handleRegistration(scope.row.studentId,scope.row.eventId)"> 撤销报名 </el-dropdown-item> -->
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </template>

          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <!-- 编辑信息 -->
    <el-dialog
      v-model="info_modal"
      title="编辑信息"
      class="info-modal"
      width="960px"
    >
      <InfoForm
        ref="InfoModal"
        @sub="info_modal=false;handleLoad(true)"
      />
    </el-dialog>
    <div class="pagination">
      <el-pagination
        background
        layout="prev, pager, next, total"
        :total="total"
        @current-change="handlePage"
      />
    </div>
  </div>
  <BatchImportIntegralModal
    ref="BatchImportIntegralModalRef"
    @closed="()=>{handleLoad(true)}"
  />
  <BatchImportgradeModal
    ref="BatchImportgradeModalRef"
    @closed="()=>{handleLoad(true)}"
  />
  <BatchImportawardsModal
    ref="BatchImportawardsModalRef"
    @closed="()=>{handleLoad(true)}"
  />
</template>

<script  setup>
import {
  Search, Edit, Delete, Document
} from "@element-plus/icons-vue";
import { onMounted, ref, nextTick } from "vue";
import { usePage } from "@/hooks/usePage"
import InfoForm from "./components/stu-info-form.vue"
import { ElMessage, ElMessageBox } from 'element-plus';
import { getAllStudent, } from "@/api/manage/organcommitmenu/index"
import { withdrawalRegistration, auditCompetitionStudent } from '@/api/manage/agentmenu/index.js'
import { DeleteStudentApi } from "@/api/manage/institution"
import InstitutionSelect from "@/components/institution-select/index.vue"
import OrganizingSelect from "@/components/organizing-select/index.vue"
import BatchImportIntegralModal from "./modal/batch-import-integral.vue"
import BatchImportawardsModal from "./modal/batch-import-awards.vue"
const BatchImportIntegralModalRef = ref();
const BatchImportawardsModalRef = ref();
// 表格数据
const {
  total: total,
  data: tableData,
  query_data,
  loading,
  handleLoad,
  handlePage
} = usePage({
  api_fn: getAllStudent,
  q_data: {
    studentName: '',
    phone: "",
    agentId: "",
    institutionId: ""
  }
})


// input变化
const changeInp = () => {
  handleLoad(true)
}
/**
 * 信息弹窗数据
 */
const info_modal = ref(false)
const InfoModal = ref();
/**
 * 操作
 */
const handleOperate = (command, row) => {
  if (command == 'edit-info') {
    // 更新
    info_modal.value = true;
    nextTick(() => {
      InfoModal.value.handleGetInfo(row)
    })
  } else if (command == 'delect-item') {
    // 删除
    ElMessageBox.confirm('是否删除该选手', "提示", {
      "cancel-button-text": "取消",
      "confirm-button-text": "确定",
    }).then(async () => {
      let res = await DeleteStudentApi({
        studentId: row.studentId
      })
      if (!res.success) {
        ElMessage.error(res.message);
      } else {
        ElMessage.success(res.message);
      }

    })
  }
}

// 修改参赛审核状态
// studentId=5&status=3
const handlechange = async (row) => {
  let res = await auditCompetitionStudent({ studentId: row.studentId, status: row.entryState, eventId: row.eventId })

  if (res.success) {
    ElMessage({
      title: '成功',
      message: `${res.message}`,
      type: 'success',
    })
  } else {
    ElMessage.error(res.message)
  }
}

/**
 * 打开批量导入积分弹窗
 */
const handleOpenBatchImportModal = () => {
  BatchImportIntegralModalRef.value.handleOpenModal();
}


const handleOpenBatchAwardsModal = () => {
  BatchImportawardsModalRef.value.handleOpenModal();
}
onMounted(() => {
  handleLoad(true)
})
</script>

<style lang="scss" scoped>
.header_information {
  padding: 20px;
  .header_name {
    margin-left: 10px;
    margin-right: 10px;
    .header_text {
      margin-left: -10px;
      margin-right: -10px;
    }
    h1 {
      font-size: 28px;
    }
    // 线
    .header_line {
      display: block;
      height: 1px;
      width: 100%;
      margin: 24px 0 20px 0;
      background-color: #8473f717;
    }
  }
  //   内容
  :deep(.table_btn_success) {
    padding: 0 5px !important;
    border: none;
  }
  :deep(.el-table) .cell {
    padding: 0 10px;
  }
  .el_row_btn {
    margin-bottom: 20px;
    .content {
      .content_top_btn {
        display: flex;
        justify-content: space-between;
        .top_search_inp {
          width: 300px;
          height: 40px;
          margin-right: 5px;
        }
        .top_search_btn {
          width: 110px;
          margin-right: 5px;
        }
      }
    }
  }
  .el-radio {
    margin: 0 0 0 5px;
  }
  .el_dropdown_link {
    font-size: 14px;
  }
  :deep(.el-table)__cell {
    padding: 12px 0 !important;
  }
  // 分页
  .pagination {
    margin-top: 30px;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 50px;
  }
}
</style>
